package tools.svg;

import java.io.OutputStreamWriter;
import java.io.Writer;

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Text2SVGGenerator {

	public static void main(String[] args)throws Exception{
		Text2SVG("");
	}
	
	public static Document Text2SVG(String s)throws Exception{
		String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
		DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
		Document doc = impl.createDocument(svgNS, "svg", null);
		
		Element svgRoot =doc.getDocumentElement();
		svgRoot.setAttributeNS(null, "width", "400");
		svgRoot.setAttributeNS(null, "height", "450");

//		 Create the rectangle.
		Element rectangle = doc.createElementNS(svgNS, "rect");
		rectangle.setAttributeNS(null, "x", "10");
		rectangle.setAttributeNS(null, "y", "20");
		rectangle.setAttributeNS(null, "width", "100");
		rectangle.setAttributeNS(null, "height", "50");
		rectangle.setAttributeNS(null, "fill", "red");

//		 Attach the rectangle to the root 'svg' element.
		svgRoot.appendChild(rectangle);

		Writer out= new OutputStreamWriter(System.out,"UTF-8");
		SVGGraphics2D svgGen=new SVGGraphics2D(doc);
		svgGen.stream(out,false);
		
		return doc;
	}
}
